﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using DataTools;

namespace HorizonFlightGenerator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnGenerate_Click(object sender, EventArgs e)
        {
            DataAccess da = new DataAccess(@".\SQLServer", "software", "software1", "Horizon");

            int loops = Math.Abs(TimeSpan.FromTicks(datePickFrom.Value.Ticks).Days - TimeSpan.FromTicks(datePickTo.Value.Ticks).Days);

            int no = 1;

            for (int x = 0; x < loops; x++)
            {
                string flightNo = "";
                if (no < 10)
                    flightNo="000";
                else if (no < 100)
                    flightNo = "00";
                else if (no < 1000)
                    flightNo = "0";

                switch (datePickFrom.Value.AddDays((double)x).DayOfWeek)
                {
                    case DayOfWeek.Monday:
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','NY-NO','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','A330','11:30','18:17',7,18,42,280)");
                        no++;
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','NY-PI','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','A330','08:55','10:44',3,18,42,280)");
                        no++;
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','NO-NY','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','A330','06:20','12:31',7,18,42,280)");
                        no++;
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','PI-NY','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','A330','07:00','08:30',9,18,42,280)");
                        no++;
                        break;
                    case DayOfWeek.Tuesday:
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','NY-MI','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','B747','06:30','11:45',3,12,28,300)");
                        no++;
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','NY-ME','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','B747','06:30','10:10',5,12,28,300)");
                        no++;
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','MI-NY','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','B747','12:20','05:50',8,12,28,300)");
                        no++;
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','ME-NY','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','B747','06:20','12:10',10,12,28,300)");
                        no++;
                        break;
                    case DayOfWeek.Wednesday:
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','NY-CH','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','A330','08:55','12:00',1,18,42,280)");
                        no++;
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','CH-NY','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','A330','06:25','12:31',1,18,42,280)");
                        no++;
                        break;
                    case DayOfWeek.Thursday:
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','NY-NO','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','A330','11:30','18:17',7,18,42,280)");
                        no++;
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','NY-PI','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','A330','08:55','10:44',3,18,42,280)");
                        no++;
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','NO-NY','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','A330','06:20','12:31',7,18,42,280)");
                        no++;
                        break;
                    case DayOfWeek.Friday:
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','NY-MI','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','B747','06:30','11:45',3,12,28,300)");
                        no++;
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','MI-NY','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','B747','12:20','05:50',8,12,28,300)");
                        no++;
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','PI-NY','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','A330','07:00','08:30',9,18,42,280)");
                        no++;
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','ME-NY','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','B747','06:20','12:10',10,12,28,300)");
                        no++;
                        break;
                    case DayOfWeek.Saturday:
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','NY-CH','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','A330','08:55','12:00',1,18,42,280)");
                        no++;
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','CH-NY','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','A330','06:25','12:31',1,18,42,280)");
                        no++;
                        break;
                    case DayOfWeek.Sunday:
                        da.ExecuteNonQuery("INSERT INTO Flight VALUES('HA" + flightNo + no + "','NY-ME','" + datePickFrom.Value.AddDays((double)x).ToShortDateString() + "','B747','06:30','10:10',5,12,28,300)");
                        no++;
                        break;
                }
            }
        }
    }
}
